package com.zhoutao.blog.seven.dao.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhoutao.blog.seven.dao.mapper.BookChapterMapper;
import com.zhoutao.blog.seven.dao.model.BookChapterDao;
import com.zhoutao.blog.seven.model.converter.BookChapterConverter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
@RequiredArgsConstructor
public class BookChapterRepository extends ServiceImpl<BookChapterMapper, BookChapterDao> {

    private final BookChapterConverter chapterConverter;


    public List<BookChapterDao> findByBookId(Long bookId) {

        // 查询并排序
        LambdaQueryWrapper<BookChapterDao> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BookChapterDao::getBookId, bookId);
        wrapper.orderByAsc(BookChapterDao::getOrdinal);
        return this.baseMapper.selectList(wrapper);
    }

    public List<Long> findBookIdsOfExistChapter() {
        return this.baseMapper.bookIds();
    }
}
